package com.jxdinfo.hussar.cloud.module.example.lift.controller;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jxdinfo.hussar.cloud.module.example.lift.dto.LiftTimeCountChartDto;
import com.jxdinfo.hussar.cloud.module.example.lift.dto.LiftTimeCountSearchDto;
import com.jxdinfo.hussar.cloud.module.example.lift.model.LiftTimeCount;
import com.jxdinfo.hussar.cloud.module.example.lift.service.LiftTimeCountService;
import com.jxdinfo.hussar.platform.core.base.apiresult.ApiResponse;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * 升降机工时统计(LiftTimeCount)表控制层
 *
 * @author makejava
 * @since 2023-10-23 18:32:14
 */
@RestController
@RequestMapping("liftTimeCount")
public class LiftTimeCountController  {
    /**
     * 服务对象
     */
    @Resource
    private LiftTimeCountService liftTimeCountService;

    /**
     * 分页查询所有数据
     *
     * @param page 分页对象
     * @param liftTimeCount 查询实体
     * @return 所有数据
     */
    @GetMapping
    public ApiResponse selectAll(Page<LiftTimeCount> page, LiftTimeCount liftTimeCount) {
        return ApiResponse.success(this.liftTimeCountService.page(page, new QueryWrapper<>(liftTimeCount)));
    }
    /**
     * 升降机工时分析图表
     * @param liftTimeCountSearchDto
     * @return
     */
    @PostMapping("/findByChart")
    public ApiResponse<List<LiftTimeCountChartDto>> findByChart(LiftTimeCountSearchDto liftTimeCountSearchDto) {
        if (liftTimeCountSearchDto == null){
            return null;
        }

        if(ObjectUtils.isNotEmpty(liftTimeCountSearchDto.getTyProjectCode())){
            liftTimeCountSearchDto.setTyProjectCode(liftTimeCountSearchDto.getTyProjectCode());
        }else{
           // liftTimeCountSearchDto.setTyProjectCode(ProjectUtil.getProjectInfo().getProjectCode());
        }

        return ApiResponse.success(liftTimeCountService.findByChart(liftTimeCountSearchDto));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ApiResponse selectOne(@PathVariable Serializable id) {
        return ApiResponse.success(this.liftTimeCountService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param liftTimeCount 实体对象
     * @return 新增结果
     */
    @PostMapping
    public ApiResponse insert(@RequestBody LiftTimeCount liftTimeCount) {
        return ApiResponse.success(this.liftTimeCountService.save(liftTimeCount));
    }

    /**
     * 修改数据
     *
     * @param liftTimeCount 实体对象
     * @return 修改结果
     */
    @PutMapping
    public ApiResponse update(@RequestBody LiftTimeCount liftTimeCount) {
        return ApiResponse.success(this.liftTimeCountService.updateById(liftTimeCount));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping
    public ApiResponse delete(@RequestParam("idList") List<Long> idList) {
        return ApiResponse.success(this.liftTimeCountService.removeByIds(idList));
    }
}

